package game

import (
	"context"

	"gitee.com/shiwjlinux/arm/common"
	"gitee.com/shiwjlinux/arm/ioc"
)

func GetService() Service {
	return ioc.Controller.Get(AppName).(Service)
}

type Service interface {
	SyncGame(context.Context, *SyncGameSet, SyncGameHandleFunc) (*Game, error)
	CreateGame(context.Context, *CreateGameRequest) (*Game, error)
	UpdateGame(context.Context, *UpdateGameRequest) (*Game, error)
	QueryGame(context.Context, *QueryGameRequest) (*GameSet, error)
	DescribeGame(context.Context, *DescribeGameRequest) (*Game, error)
}

type SyncGameHandleFunc func(GameResponse)

type GameResponse struct {
	Success  bool
	GameName string `json:"game_name"`
	Message  string `json:"message"`
}

func (gr *GameResponse) String() string {
	return common.ToJsonString(gr)
}

type QueryGameRequest struct {
	*common.PageRequest
	GameName    string `json:"game_name"`
	PackageName string `json:"package_name"`
}

type DescribeGameRequest struct {
	Id          string `json:"id"`
	PackageName string `json:"package_name"`
}

func NewDescribeGameRequestById(id string) *DescribeGameRequest {
	return &DescribeGameRequest{
		Id: id,
	}
}

func NewDescribeGameRequestByPackageName(packageName string) *DescribeGameRequest {
	return &DescribeGameRequest{
		PackageName: packageName,
	}
}

type UpdateGameRequest struct {
	*CreateGameRequest
}

func NewUpdateGameRequest() *UpdateGameRequest {
	return &UpdateGameRequest{
		CreateGameRequest: NewCreateGameRequest(),
	}
}

func NewUpdateGameRequestByPackageName(packageName string) *UpdateGameRequest {
	c := NewCreateGameRequest()
	c.PackageName = packageName
	return &UpdateGameRequest{
		CreateGameRequest: c,
	}
}
